package com.topscomm.ywxt;

import com.topscomm.cbo.service.ICboAttachmentService;
import com.topscomm.cbo.service.ICboAttachmentTypeService;
import com.topscomm.pub.util.ConvertUtil;
import com.topscomm.pub.util.SpringUtil;
import com.topscomm.tap.security.SecurityUserDetails;
import com.topscomm.test.TestYWXTConvertService;

public class cboattachService extends TestYWXTConvertService {
    private ICboAttachmentService cboAttachmentService = (ICboAttachmentService) SpringUtil.getBean("cboAttachmentService");
    private ICboAttachmentTypeService cboAttachmentTypeService = (ICboAttachmentTypeService) SpringUtil.getBean("cboAttachmentTypeService");
    /**
     * 批量插入附件
     * 项目文件迁移；注意：迁移完成后需要在服务器中拷贝附件！！！！！！！！
     */
    public void convertProjectAttchment(String orgcode) throws Exception {
//        StringBufferProxy selectSql = new StringBufferProxy();
//        selectSql.appendSingle("select PROJECT.code,FILE_HANDLE.* from PROJECT LEFT JOIN FILE_HANDLE ON FILE_HANDLE.RID = PROJECT.NBBH where PROJECT.orgcodenew = '{0}' " +
//                "AND FILE_HANDLE.rid is NOT null and PROJECT.fee != 0", orgcode);
//        List<Map> maps = selectCpm(selectSql.toString());
//        for (Map item : maps) {
//            CboAttachmentEntity entity = new CboAttachmentEntity();
//            PmProjectEntity pmProjectEntity = this.queryPmProjectByCode(ConvertUtil.convertToString(item.get("code"))).get(0);
//            entity.setSourcetype("PmProjectAttachment");
//            entity.setSourceid(pmProjectEntity.getId());
//            // 查询附件类型id
//            List<CboAttachmentTypeEntity> cboAttachmentTypeEntities = cboAttachmentTypeService.queryByWhere("SOURCETYPE ='PmProjectAttachment'");
//            entity.setAttachmenttypeid(cboAttachmentTypeEntities.get(0).getId());
//            String savepath = ConvertUtil.convertToString(item.get("SAVEPATH"));
//            entity.setSavepath(savepath.substring(1,savepath.length()));
//            entity.setFilename(ConvertUtil.convertToString(item.get("FILENAME")));
//            entity.setDisplayname(ConvertUtil.convertToString(item.get("DISPLAYNAME")));
//            entity.setFiletype(ConvertUtil.convertToString(item.get("FILETYPE")));
//            entity.setFilesize(ConvertUtil.convertToString(item.get("FILESIZE")));
//            entity.setPwd(ConvertUtil.convertToString(item.get("PWD")));
//            entity.setDescription(ConvertUtil.convertToString(item.get("NOTES")));
//            entity.setUploaddate(ConvertUtil.convertToDate(item.get("SCSJ")));
//            entity.setCreateon(ConvertUtil.convertToDate(item.get("SCSJ")));
//            SecurityUserDetails scrid = getUserDetailsByYWXTUerId(ConvertUtil.convertToString(item.get("SCRID")));
//            entity.setCreateorgid(scrid.getOrg().getId());
//            entity.setCreateuser(scrid.getUser().getId());
//            entity.setModifiedon(ConvertUtil.convertToDate(item.get("SCSJ")));
//            entity.setExtendfield1("1");
//            entity.setExtendfield2("3");
//            entity.setExtendfield3("科远迁移项目文件数据");
//            cboAttachmentService.getDao().insert(entity);
//        }
        //SecurityUserDetails djrDetails = getUserDetailsByYWXTUerId(ConvertUtil.convertToString("666"));
    }
}
